//
//  NSDictionary+NetWork.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/19.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "NSDictionary+NetWork.h"
#import "NSString+Tool.h"
#import <YYModel/YYModel.h>
@implementation NSDictionary (NetWork)

- (NSString *)parametersString:(NSDictionary *)parameters
{
    NSMutableDictionary *mutableParameters = [parameters mutableCopy];
    NSArray *tempKeys = [mutableParameters allKeys];
    
    NSArray *sortedKeys = [tempKeys sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        NSString *key1 = (NSString *)obj1;
        NSString *key2 = (NSString *)obj2;
        return [key1 compare:key2];
    }];
    
    NSMutableArray *tempArr = [NSMutableArray array];
    [tempArr addObjectsFromArray:sortedKeys];
    
    NSString *token = @"";
    for (NSString *key in tempArr) {
        NSString *value = [NSString stringWithFormat:@"%@", parameters[key]];
        token = [token stringByAppendingString:value];
    }
    token = [token stringByAppendingString:@"1e56c95504a9a846e4c7043704a20f25"];
    token = [token md5];
    
    [mutableParameters addEntriesFromDictionary:@{@"token": token}];
    return [mutableParameters yy_modelToJSONString];
}

@end
